package com.zxc.shortlink.config;

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
* @author zxc_user
* @date 2022/3/23 23:37
* @version 1.0
* @description 线程池配置类
**/
@Component
public class ThreadPoolConfig {

    @Bean(value = "ordinaryThreadPool")
    public ThreadPoolExecutor threadPoolExecutor() {
        int thread = Runtime.getRuntime().availableProcessors();
        return new ThreadPoolExecutor(thread, thread, 120, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
    }

    @Bean(value = "shortLinkThreadPool")
    public ThreadPoolExecutor shortLinkThreadPool() {
        int thread = Runtime.getRuntime().availableProcessors();
        return new ThreadPoolExecutor(thread, thread, 120, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
    }
}
